package com.qf.booot2.controller;

import com.wf.captcha.ChineseGifCaptcha;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;

import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @auther x
 * @date 2022/5/19 16:10
 */
@Controller
public class JspController {
    @GetMapping("/")
    public String index(Model model){
        model.addAttribute("name","张三");
        model.addAttribute("age",19);
        return "index";
    }


    @GetMapping("/captcha")
    public void captcha(HttpServletResponse response) throws IOException {
        // 获取响应流
        ServletOutputStream outputStream = response.getOutputStream();
        // 算术计算的验证码
        // ArithmeticCaptcha arithmeticCaptcha = new ArithmeticCaptcha();
        // 设置计算的长度
        // arithmeticCaptcha.setLen(3);
        // 获取验证码的文字
        // System.out.println(arithmeticCaptcha.text());
        // 获取验证码的图片并设置给响应流
        // arithmeticCaptcha.out(outputStream);

        // 验证英文和数字的验证
        // SpecCaptcha chineseGifCaptcha = new SpecCaptcha();
        // chineseGifCaptcha.setLen(5);
        // chineseGifCaptcha.setCharType(2);
        // System.out.println(chineseGifCaptcha.text());
        // chineseGifCaptcha.out(outputStream);

        // 中文验证码
        // ChineseCaptcha chineseGifCaptcha = new ChineseCaptcha();
        // chineseGifCaptcha.setLen(5);
        // System.out.println(chineseGifCaptcha.text());
        // chineseGifCaptcha.out(outputStream);

        // 动图验证码
        // GifCaptcha chineseGifCaptcha = new GifCaptcha();
        // chineseGifCaptcha.setLen(5);
        // System.out.println(chineseGifCaptcha.text());
        // chineseGifCaptcha.out(outputStream);

        // 中文的动图效果
        ChineseGifCaptcha chineseGifCaptcha = new ChineseGifCaptcha();
        chineseGifCaptcha.setLen(5);
        System.out.println(chineseGifCaptcha.text());
        chineseGifCaptcha.out(outputStream);

    }



}
